package com.iclippi.server.model;

import java.util.Collections;

import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheFactory;
import javax.cache.CacheManager;

public class ClippyCache {

	private static ClippyCache singleton = null;

	private Cache cache;

	private ClippyCache() throws CacheException {
		CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
		cache = cacheFactory.createCache(Collections.emptyMap());
	}
	
	public static ClippyCache getInstance() throws CacheException{
		if (singleton==null) singleton=new ClippyCache();
		return singleton;
	}
	
	public static void clearCache() {
		singleton.cache.clear();
	}
	
	public Long getClipboardId(String clipboardName){
		String cacheClipboardName="ClipName - "+clipboardName;
		return (Long) cache.get(cacheClipboardName);
	}
	
	@SuppressWarnings("unchecked")
	public void setClipboardId(String clipboardName, Long Id){
		String cacheClipboardName="ClipName - "+clipboardName;
		cache.put(cacheClipboardName, Id);
	}
	
	public Long getClipboardVersion(String clipboardName){
		String cacheClipboardName="ClipVersion - "+clipboardName;
		return (Long) cache.get(cacheClipboardName);
	}
	
	@SuppressWarnings("unchecked")
	public void setClipboardVersion(String clipboardName, Long Id){
		String cacheClipboardName="ClipVersion - "+clipboardName;
		cache.put(cacheClipboardName, Id);
	}
	


}
